package Zuoye.zuoye3;

import java.util.Arrays;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double[] heights = new double[5];
        for (int i = 0; i < heights.length; i++) {
            System.out.println("请输入学生身高：");
            double height = sc.nextDouble();
            heights[i] = height;
        }
        System.out.println("学生身高："+Arrays.toString( heights));
        //定义冒泡工具
        Mao(heights);
        System.out.println("----------------------");
        System.out.println("冒泡排序后的身高"+Arrays.toString(heights));
        System.out.println("----------------------");
        //定义选择排序工具
        Pai(heights);
        System.out.println("选择排序后的身高：" +Arrays.toString( heights));
    }

    private static void Pai(double[] heights) {
        for (int i = 0; i < heights.length-1; i++) {
            for (int i1 = i+1; i1 < heights.length; i1++) {
                if (heights[i]> heights[i1]){
                    double temp = heights[i];
                    heights[i] = heights[i1];
                    heights[i1] = temp;
                }
            }
        }
    }

    private static void Mao(double[] heights) {
        for (int i = 0; i < heights.length; i++) {
            for (int i1 = 0; i1 < heights.length-1-i; i1++) {
                if (heights[i1]> heights[i1+1]){
                    double temp = heights[i1];
                    heights[i1] = heights[i1+1];
                    heights[i1+1] = temp;
                }
            }
        }
    }


}
